package com.travel.rabbit.enums;

import java.util.EnumSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 云澜
 * @date 2021/12/22 2:44 下午
 */
public enum BusinessEnum {
    SUCCESS(200,"成功"),
    ERROR(500,"系统异常"),

    MERCHANT_EXIST(2001,"商家名称已存在"),
    CATEGORY_EXIST(2002,"分类名称已存在"),
    USER_UNAUTHORIZED(2003,"用户无操作权限"),
    /*REGISTER_SUCCESS(2001,"恭喜您,注册成功!"),
    MOBILE_EXIST(3001,"手机号已存在,不允许重复注册"),
    NICKNAME_EXIST(3002,"昵称已存在,不允许重复注册"),
    MOBILE_NOT_EXIST(3003,"手机号不存在，请检查手机号是否输入正确"),
    USER_NOT_EXIST(3004,"用户不存在"),
    VALIDATE_CODE_ERROR(3005,"验证码错误，请重新输入"),
    VALIDATE_CODE_NOT_EXPIRE(3006,"您的验证码还在有效期，请勿重复操作"),
    USER_STATUS_DISABLE(3007,"您的账号处于异常状态,请联系管理员进行处理")*/
    ;


    ;

    /**
     * 根据code 找到desc 描述
     */
    private static final Map<Integer, BusinessEnum> valueLookup = new ConcurrentHashMap<>(values().length);
    static {
        for (BusinessEnum type: EnumSet.allOf( BusinessEnum.class)){
            valueLookup.put(type.code, type);
        }
    }


    public static BusinessEnum fromValue(Integer code) {
        BusinessEnum data = valueLookup.get(code);
        if (data == null) {
            throw new IllegalArgumentException("参数[" + code + "]不正确，没有找到对应的 Enum");
        }
        return data;
    }
    BusinessEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Integer code;
    private String  msg;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
